<template>
  <el-carousel :interval="5000" arrow="always" height="500px" width="100%">
    <!--自适应  :height="bannerHeight + 'px' -->
    <el-carousel-item v-for="(item,index) in imgList" v-if="index < 3" :key="item.id">
      <img
        :src="item.image"
        class="image"
        ref="bannerHeight"
         :onerror="defalutLogoUrl"
      />
      <!--         @load="imgload" -->
    </el-carousel-item>
  </el-carousel>

</template>

<script>
export default {
  data() {
    return {
      bannerHeight: "",
      imgList:[],
       defalutLogoUrl:'this.src="'+  require("../../assets/img/6.jpg")  +'"',
    };
  },
  methods: {
    // 轮播图窗口适应
    // imgload() {
    //   this.$nextTick(() => {
    //     this.bannerHeight = this.$refs.bannerHeight[0].Height;
    //   });
    // },
    async getChart(){
      const res = await this.http.get('/chart/select')
      this.imgList = res.list;
      console.log(res);
    }
  },
  //增加监听事件,当视口发生改变时,得到此时的图片高度赋值给bannerHeight
  mounted() {
    // this.imgload();
    // window.addEventListener(
    //   "resize",
    //   () => {
    //     this.bannerHeight = this.$refs.bannerHeight[0].height;
    //     this.imgload();
    //   },
    //   false
    // );
  },
  created(){
    this.getChart();
  }
};
</script>

<style scoped>
.image {
  background: #c8cfd8;
  width: 80%;
  text-align: center;
  margin-left: 142px;
  width: 80.6%;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  /* margin: 0;- */
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
